package com.yuxi.al.leercode;

/**
 * Created by yuxi on 2017/4/5.
 */
public class RervseString {
    public static void main(String[] args) {
        String str = "hello";
        System.out.println(reverseString(str));
    }
    //把一个字符串逆序输出
    public static String reverseString(String str) {
        if (str == null)
            return null;
        char[] characters = str.toCharArray();
        char[] chars = new char[characters.length];
        int j = 0;
        for (int i = characters.length - 1; i >= 0; i--) {
            chars[j++] = characters[i];
        }
        return new String(chars);
    }
}
